<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        .box{
            width: 320px;
            height: 320px;
            border: 1px solid black; 
        }
        *{
            text-align: center;
            margin: 0px auto;
        }
        
        .ss{
             width: 18px;
            height: 18px;
            border: 1px solid black;
            float: left;
            
        }
        .bg{
            background-color: green;
        }
        .bg-active{
            background-color:lightcoral;
        }

    </style>
</head>
<body>
    <div class="box" id="box"></div>
</body>
<script>
    var init=function(){
        var box=document.getElementById("box");
        for(var i=1;i<=256;i++){
            var div=document.createElement("div");
            div.className="ss bg";
            div.onmouseover=function(){
                this.className="ss bg-active";
            } 
            div.onmouseout=function(){
                this.className="ss bg";
            }
            var a=function(k){
                div.onclick = function()
                {
                alert(k);
                }
        }
        a(i);
        box.appendChild(div);
        }
        if(true){
        console.log(i);
        }
    }
    init();
</script>
</html>